package net.test.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;


import net.test.bean.Pager;
import net.test.dao.BaseDao;
import net.test.service.BaseService;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service实现类 - Service实现类基类
 */

@Transactional
public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {

	private BaseDao<T, PK> baseDao;

	public BaseDao<T, PK> getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao<T, PK> baseDao) {
		this.baseDao = baseDao;
	}
	
	@Transactional(readOnly = true)
	public T get(PK id) {
		return baseDao.get(id);
	}

	@Transactional(readOnly = true)
	public T load(PK id) {
		return baseDao.load(id);
	}

	@Transactional(readOnly = true)
	public List<T> getAllList() {
		return baseDao.getAllList();
	}
	
	@Transactional(readOnly = true)
	public Long getTotalCount() {
		return baseDao.getTotalCount();
	}

	@Transactional
	public PK save(T entity) {
		return baseDao.save(entity);
	}

	@Transactional
	public void update(T entity) {
		baseDao.update(entity);
	}
	
	@Transactional
	public void delete(T entity) {
		baseDao.delete(entity);
	}

	@Transactional
	public void delete(PK id) {
		baseDao.delete(id);
	}

	@Transactional
	public void delete(PK[] ids) {
		baseDao.delete(ids);
	}

	@Transactional(readOnly = true)
	public void flush() {
		baseDao.flush();
	}

	@Transactional(readOnly = true)
	public void evict(Object object) {
		baseDao.evict(object);
	}
	
	@Transactional(readOnly = true)
	public void clear() {
		baseDao.clear();
	}
	
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager) {
		return baseDao.findPager(pager);
	}
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager,boolean isMoreSearch){
		return baseDao.findPager(pager,isMoreSearch);
	}
	
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager, Criterion... criterions) {
		return baseDao.findPager(pager, criterions);
	}
	
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager, Order... orders) {
		return baseDao.findPager(pager, orders);
	}
	
	@Transactional(readOnly = true)
	public Pager findPager(Pager pager, Criteria criteria) {
		return baseDao.findPager(pager, criteria);
	}
	
	/**
	 * 根据list封装pager
	 * @param pager
	 * @param list
	 * @return Pager
	 */
	@Transactional(readOnly = true)
	public Pager getPager(Pager pager,List<?> list) {
		// TODO Auto-generated method stub
		pager.setResult(list);
		pager.setTotalCount(list.size());
		return pager;
	}
	
	public Integer getCountByProperty(Map<String, String> params, String objectName, String objectValue) {
		// TODO Auto-generated method stub
		return baseDao.getCountByProperty(params, objectName, objectValue);
	}
	
	public List getListByProperty(Map<String, String> params,
			String objectName, String objectValue, Pager pager) {
		// TODO Auto-generated method stub
		return baseDao.getListByProperty(params, objectName, objectValue, pager);
	}
	public String[] getColumnName(){
		return baseDao.getColumnName();
	}
	public void setEntityClass(Class<T> entityClass){
		baseDao.setEntityClass(entityClass);
	}
	public List findObjByHql(String hql){
		return baseDao.findObjByHql(hql);
	}
}